# Tests report generator using test results published by CI Build workflow
# https://github.com/marketplace/actions/test-reporter

name: '📝 CI Tests Report'

on:
  workflow_run:
    workflows: [ '🏗️ CI Build' ]
    types:
      - completed

jobs:
  test-report:
    name: ${{ matrix.name }} Test Report
    if: ${{ github.event.workflow_run.conclusion != 'skipped' }}
    runs-on: ubuntu-latest
    permissions:
      checks: write
      pull-requests: write
      actions: read

    strategy:
      fail-fast: false
      matrix:
        include:
          - name: "Win64_DX_Release"
          - name: "Win64_VK_Release"
          - name: "Win32_DX_Release"
          - name: "Win32_VK_Release"
          - name: "Ubuntu_VK_Release"
          - name: "MacOS_VK_Release"
          - name: "MacOS_MTL_Release"

    steps:
      - name: Download Event File
        uses: dawidd6/action-download-artifact@246dbf436b23d7c49e21a7ab8204ca9ecd1fe615
        with:
          run_id: ${{ github.event.workflow_run.id }}
          name: EventFile
          path: EventFile

      - name: Download Test Results
        uses: dawidd6/action-download-artifact@v3
        with:
          run_id: ${{ github.event.workflow_run.id }}
          name: ^MethaneKit_${{ matrix.name }}_TestResults_.*$
          name_is_regexp: true
          path: TestResults
          allow_forks: true

      - name: Publish Test Results
        uses: EnricoMi/publish-unit-test-result-action/composite@v2
        if: ${{ success() || failure() }}
        with:
          check_name: ${{ matrix.name }} Test Results
          comment_title: ${{ matrix.name }} Test Results
          files: TestResults/**/*Test.xml
          event_file: EventFile/event.json
          commit: ${{ github.event.workflow_run.head_sha }}
          event_name: ${{ github.event.workflow_run.event }}
          action_fail: true
          action_fail_on_inconclusive: true
